//
//  ZQNavigationController.swift
//  新浪微博
//
//  Created by huami on 2019/10/10.
//  Copyright © 2019 huami. All rights reserved.
//

import UIKit

class ZQNavigationController: UINavigationController {

    override func viewDidLoad() {
        super.viewDidLoad()
        navigationBar.isHidden = true
     }
        
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        print(viewController)
        
        if children.count  > 0 {
            viewController.hidesBottomBarWhenPushed = true
            
            if let vc = viewController as? ZQBaseViewController {
                
                var title = "返回"
                
                if children.count == 1 {
                    title = children.first?.title ?? "返回"
                }
                
                vc.navItem.leftBarButtonItem = UIBarButtonItem(title: title, target: self, action: #selector(popToParent), isBack:true)
            }
        }
        
        super.pushViewController(viewController, animated: true)
    }
    
   @objc private func popToParent() {
        popViewController(animated: true)
    }
}
